package cn.iocoder.yudao.module.of.controller.admin.userremindsetup;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.of.controller.admin.userremindsetup.vo.*;
import cn.iocoder.yudao.module.of.dal.dataobject.userremindsetup.UserRemindSetupDO;
import cn.iocoder.yudao.module.of.service.userremindsetup.UserRemindSetupService;

@Tag(name = "管理后台 - 日程提醒设置")
@RestController
@RequestMapping("/of/user-remind-setup")
@Validated
public class UserRemindSetupController {

    @Resource
    private UserRemindSetupService userRemindSetupService;

    @PostMapping("/create")
    @Operation(summary = "创建日程提醒设置")
    @PreAuthorize("@ss.hasPermission('of:user-remind-setup:create')")
    public CommonResult<Long> createUserRemindSetup(@Valid @RequestBody UserRemindSetupSaveReqVO createReqVO) {
        return success(userRemindSetupService.createUserRemindSetup(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新日程提醒设置")
    @PreAuthorize("@ss.hasPermission('of:user-remind-setup:update')")
    public CommonResult<Boolean> updateUserRemindSetup(@Valid @RequestBody UserRemindSetupSaveReqVO updateReqVO) {
        userRemindSetupService.updateUserRemindSetup(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除日程提醒设置")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('of:user-remind-setup:delete')")
    public CommonResult<Boolean> deleteUserRemindSetup(@RequestParam("id") Long id) {
        userRemindSetupService.deleteUserRemindSetup(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得日程提醒设置")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('of:user-remind-setup:query')")
    public CommonResult<UserRemindSetupRespVO> getUserRemindSetup(@RequestParam("id") Long id) {
        UserRemindSetupDO userRemindSetup = userRemindSetupService.getUserRemindSetup(id);
        return success(BeanUtils.toBean(userRemindSetup, UserRemindSetupRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得日程提醒设置分页")
    @PreAuthorize("@ss.hasPermission('of:user-remind-setup:query')")
    public CommonResult<PageResult<UserRemindSetupRespVO>> getUserRemindSetupPage(@Valid UserRemindSetupPageReqVO pageReqVO) {
        PageResult<UserRemindSetupDO> pageResult = userRemindSetupService.getUserRemindSetupPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, UserRemindSetupRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出日程提醒设置 Excel")
    @PreAuthorize("@ss.hasPermission('of:user-remind-setup:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportUserRemindSetupExcel(@Valid UserRemindSetupPageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<UserRemindSetupDO> list = userRemindSetupService.getUserRemindSetupPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "日程提醒设置.xls", "数据", UserRemindSetupRespVO.class,
                        BeanUtils.toBean(list, UserRemindSetupRespVO.class));
    }

}